package com.avecsys.quotemanager.mbeans.security;

import javax.faces.context.FacesContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.avecsys.quotemanager.exception.BaseException;
import com.avecsys.quotemanager.service.common.CommonService;
import com.avecsys.quotemanager.utils.MessageBoardUtil;
import com.avecsys.quotemanager.utils.TransactionStatus;

/**
 * @author sam sundar
 *
 */
public class VerifyEmailMBean {

	private final Log log = LogFactory.getLog(VerifyEmailMBean.class);

	private CommonService commonService;

	public CommonService getCommonService() {
		return commonService;
	}

	public void setCommonService(CommonService commonService) {
		this.commonService = commonService;
	}

	public void validateEmailAddress() {
		MessageBoardUtil.resetMessageBoard();
		String verificationToken = FacesContext.getCurrentInstance()
				.getExternalContext().getRequestParameterMap()
				.get("verifytoken");
		try {
			if (verificationToken != null) {
				TransactionStatus transactionStatus = commonService
						.activateEmail(verificationToken);
			}
		} catch (BaseException e) {
			log.error(e);
			MessageBoardUtil.publishException(e);
		} catch (Exception e) {
			log.error(e);
			MessageBoardUtil.publishException(e);
		}
	}
}
